|
Writing custom wizards
You can extend functionality of FastReport with the help of so-called wizards. FastReport, for example, contains the standard "Report Wizard," which is called from the "File|New…" menu. There are two types of wizards supported in FastReport. The first type includes the wizards already mentioned, called from the "File|New…" menu. The second one includes wizards, which can be called from the "Wizards" toolbar. The basic class for any wizard is "TfrxCustomWizard," defined in the "frxClass" file. TfrxCustomWizard = class (TComponent) public class function GetDescription: String ; virtual ; abstract ; function Execute: Boolean; virtual ; abstract ; property Designer: TfrxCustomDesigner read FDesigner; property Report: TfrxReport read FReport; end; To write your own wizard, it is necessary to inherit from this class and override at least the "GetDescription" and "Execute" methods. The first one returns the wizard’s name; the second one is called when running the wizard; it must return "True," if the wizard finished working successfully and brought any changes to the report. During the wizard’s working, you can call methods and properties of the designer and the report properly via the "Designer" and "Report" properties. Registration and deleting of the wizard is performed via the procedures described in the "frxDsgnIntf" file: frxWizards.Register(ClassRef: TfrxWizardClass; ButtonBmp: TBitmap; IsToolbarWizard: Boolean = False); frxWizards.Unregister(ClassRef: TfrxWizardClass); At registration, one enters the name of the wizard’s class, its picture, and specifies if the wizard is placed in the "Wizards" toolbar. If the wizard should be placed in the toolbar, the ButtonBmp size must be either 16x16 pixels, or 22x22 pixels otherwise. Let us examine a primitive wizard, which is being registered in the"File|New..." menu, and then adds a new page to the report. usesfrxClass, frxDsgnIntf; type public function Execute: Boolean;override; end; class functionTfrxMyWizard.GetDescription: String ; begin end; function TfrxMyWizard.Execute: Boolean; var begin Designer.Lock; { create a new page in the report } Page := TfrxReportPage.Create(Report); { create a unique name for the page } Page.CreateUniqueName; { set sizes and orientation of paper by default } Page.SetDefaults; { update report’s pages and switch the focus to page the last added } Designer.ReloadPages(Report.PagesCount - 1); end; var initialization { load a picture from a resource; of course, you should place it there first } Bmp.LoadFromResourceName(hInstance, 'frxMyWizard'); frxWizards.Register(TfrxMyWizard, Bmp); finalization Bmp.Free; end. |